local hx__fangquan = fk.CreateSkill({
  name = "hx__fangquan",
})


hx__fangquan:addEffect("active", {
  name = "hx__fangquan",
  anim_type = "control",
  prompt = "#hx__fangquan",
  card_num = 0,
  target_num = 1,
  interaction = function(self, player)
    local choiceList = { 
      "hx__fangquan_skip",
      "hx__fangquan_draw",
      "hx__fangquan_slash",
      "hx__fangquan_turn",
    }
    local choices = {}
    local markValue = player:getMark("@hx__xiangle_yu")
    if markValue > 1 then
      table.insertTable(choices, {choiceList[1]})
    end
    if markValue > 3 then
      table.insert(choices, choiceList[2])
    end
    if markValue > 5 then
      table.insert(choices, choiceList[3])
    end
    if markValue > 7 then
      table.insert(choices, choiceList[4])
    end
    return UI.ComboBox { choices = choices, all_choices = choiceList }
  end,
  can_use = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryPhase) < 1 and
      player:getMark("@hx__xiangle_yu") > 1 and
      player:hasSkill("hx__xiangle", true)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local choice = self.interaction.data
    if choice == "hx__fangquan_skip" then
      room:removePlayerMark(player, "@hx__xiangle_yu", 2)
      room:addPlayerMark(target, "@@hx__fangquan_skip-round", 1)
    elseif choice == "hx__fangquan_draw" then
      room:removePlayerMark(player, "@hx__xiangle_yu", 4)
      room:addPlayerMark(target, "@@hx__fangquan_draw-round", 1)
    elseif choice == "hx__fangquan_slash" then
      room:removePlayerMark(player, "@hx__xiangle_yu", 6)
      local chosen = room:askToChoice(player, {
        choices = { "【杀】伤害+1", "【杀】额外结算一次" },
        skill_name = hx__fangquan.name,
        cancelable = false,
      })
      if chosen == "【杀】伤害+1" then
        room:addPlayerMark(target, "@hx__fangquan_slash_damage-round", 1)
      else
        room:addPlayerMark(target, "@hx__fangquan_slash_double-round", 1)
      end
    elseif choice == "hx__fangquan_turn" then
      room:removePlayerMark(player, "@hx__xiangle_yu", 8)
      local chosen2 = room:askToChoice(player, {
        choices = { "额外回合", "回复2点体力值" },
        skill_name = hx__fangquan.name,
        cancelable = false,
      })
      if chosen2 == "额外回合" then
        target:gainAnExtraTurn()
      else
        room:recover{
          who = target,
          num = 2,
          skillName = hx__fangquan.name,
        }
      end
    end
  end,
})

hx__fangquan:addEffect(fk.EventPhaseChanging, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__fangquan_skip-round") ~= 0 and data.phase == Player.Discard
  end,
  on_use = function(self, event, target, player, data)
    data.skipped = true
  end,
})

hx__fangquan:addEffect(fk.DrawNCards, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__fangquan_draw-round") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end,
})

hx__fangquan:addEffect(fk.CardUsing, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@hx__fangquan_slash_damage-round") ~= 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
})

hx__fangquan:addEffect(fk.CardUsing, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@hx__fangquan_slash_double-round") ~= 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
})



return hx__fangquan
